﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.ModelBinding;
using System.Web.UI;
using System.Web.UI.WebControls;
using Box.BL;
using Box.Entities;
using Microsoft.Practices.Unity;

namespace Box.Cliente.Ventas
{
    public partial class frmListVentas : System.Web.UI.Page
    {
        [Dependency]
        public IVentaBL ventaBl { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {
            PintarGrilla();
            var accion = Request.QueryString["opc"];
            var idc = Request.QueryString["id"];
            if (accion != null && accion.Equals("delete") && idc != null)
            {
                var idcc = Int32.Parse(idc.ToString());
                ventaBl.RemoveVenta(idcc);
                Response.Redirect("frmListVentas.aspx");
            }
        }
        public IEnumerable<Venta> GetVentas([Control("txtCriterio")] 
            string criterio, [Control("rbAnulado")] bool anulados, [Control("rbTodos")] bool todos)
        {
            PintarGrilla();
            return ventaBl.GetFromVentasByCriterio(criterio,anulados,todos);
        }

        private void PintarGrilla()
        {
            foreach (ListViewItem row in lvVentas.Items)
            {
                var estado = row.FindControl("cbEstado") as CheckBox;

                Panel pnlEstado = (Panel)row.FindControl("pnlEstado");
                if (estado.Checked)
                {

                    pnlEstado.CssClass = "alert alert-success";

                }
                else
                {
                    pnlEstado.CssClass = "alert alert-danger";

                }
            }
        }
    }
}